package com.atguigui.leetcode;

/**
 * 1785.构成特定和需要添加的最少元素
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/12/16 8:52
 */
public class P1785MinimumElementsToAddToFormAGivenSum {

    public static void main(String[] args) {
        Solution solution = new P1785MinimumElementsToAddToFormAGivenSum().new Solution();
        // TO TEST
    }

    class Solution {
        public int minElements(int[] nums, int limit, int goal) {
            long sum = 0;
            for (int num : nums) {
                sum += num;
            }
            //表示「当前总和」与「目标总和」的差距
            long diff = Math.abs(sum - goal);
            return (int) ((diff + limit - 1) / limit);
        }
    }
}
